﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using BLL;
using System.Data.SqlClient;
using Model;
namespace UI
{
   
    public partial class 房间和餐台管理 : Form
    {
        public static int RTID;
        public 房间和餐台管理()
        {
            InitializeComponent();
        }
        主界面 f;
        public 房间和餐台管理(主界面 f)
        {
            InitializeComponent();
            this.f = f;
        }
        public void show() {
            this.listView1.Items.Clear();
            SqlDataReader dr = 房间信息BLL.SelectAll();
            while (dr.Read())
            {
                RTID = int.Parse(dr["RTID"].ToString());
                string RTName = dr["RTName"].ToString();
                string RTConsume = dr["RTConsume"].ToString();
                string RTIsDisCount = dr["RTIsDisCount"].ToString();
                string RTMount = dr["RTMount"].ToString();

                ListViewItem li = new ListViewItem(RTName);
                
                li.SubItems.Add(RTConsume);
                li.Tag = RTID;
                if (RTIsDisCount == "True")
                {
                    li.SubItems.Add("是");
                }
                else
                {
                    li.SubItems.Add("否");
                }
                li.SubItems.Add(RTMount);
                this.listView1.Items.Add(li);

                // dataGridView1.AllowUserToAddRows = false;
                // datas();
            }
            dr.Close();
        }
        

        private void 房间和餐台管理_Load(object sender, EventArgs e)
        {
            show();
            ////断开式查询
            DataSet ds = 餐桌信息BLL.Chaxun();
            this.dataGridView1.DataSource = ds.Tables[0];

            DataSet data = 餐桌信息BLL.GaoJIBanDing();
           DataRow row = data.Tables[0].NewRow();
            row[0] = 0;
           row[1] = "全部";
            data.Tables[0].Rows.InsertAt(row,0);
            this.comboBox1.DataSource = data.Tables[0];
            this.comboBox1.ValueMember = "RTID";
            this.comboBox1.DisplayMember = "RTName";
        }
        //修改房间
        private void btnUpd_Click(object sender, EventArgs e)
        {
            if (this.listView1.SelectedItems.Count>0)
            {
                Model.房间Model.RTID = int.Parse(this.listView1.SelectedItems[0].Tag.ToString());

                房间Upd u = new 房间Upd(this.f);
                u.Show();
                this.Close();
            }
            else
            {
                MessageBox.Show("请选中");
            }
            
        }
        //删除房间，按钮点击删除
        private void btnDel_Click(object sender, EventArgs e)
        {
            if (this.listView1.SelectedItems.Count == 1)
            {
               int count= 房间信息BLL.DelFangjian(this.listView1.SelectedItems[0].Tag.ToString());
               if (count > 0)
               {
                   MessageBox.Show("删除成功");
                   房间和餐台管理_Load(null, null);
                   f.Zz();
               }
               else
               {
                   MessageBox.Show("删除失败");
               }

            }
            else
            {
                MessageBox.Show("请选择一行");
            }

        }

        private void button4_Click(object sender, EventArgs e)
        {
            餐桌添加 c = new 餐桌添加(f);
            c.Show();
            this.Close();
        }

        private void button6_Click(object sender, EventArgs e)
        {
            餐桌Model.tableID = int.Parse(this.dataGridView1.SelectedRows[0].Cells[0].Value.ToString());
            餐桌Model.TableName = this.dataGridView1.SelectedRows[0].Cells[1].Value.ToString();
            餐桌Model.RTID = this.dataGridView1.SelectedRows[0].Cells[2].Value.ToString();
            餐桌Model.TableState = this.dataGridView1.SelectedRows[0].Cells[3].Value.ToString();
            餐桌Model.TableArea = this.dataGridView1.SelectedRows[0].Cells[4].Value.ToString();
            餐桌修改 f = new 餐桌修改(this.f);
            f.Show();
            this.Close();
        }

        private void btnAdd_Click(object sender, EventArgs e)
        {
            房间Add f = new 房间Add(this.f,this);
            f.Show();
        }

        private void button7_Click(object sender, EventArgs e)
        {
            if (dataGridView1.SelectedRows.Count == 1)
            {
               餐桌Model. tableID = int.Parse(this.dataGridView1.SelectedRows[0].Cells[0].Value.ToString());
               int count = 餐桌信息BLL.CanDel();
               if (count > 0)
               {
                   MessageBox.Show("删除成功");
                   房间和餐台管理_Load(null, null);
                   f.Zz();
               }
               else
               {
                   MessageBox.Show("删除失败");
               }
            }
            else
            {
                MessageBox.Show("请选择一行");
            }
            
        }

        private void button5_Click(object sender, EventArgs e)
        {
            餐桌批量添加 f = new 餐桌批量添加(this.f);
            f.Show();
        }

        private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
        {
            餐桌Model.RTID = this.comboBox1.SelectedValue.ToString();
            if (餐桌Model.RTID.Length > 1)
            {
                餐桌Model.RTID = "0";
            }
            DataSet ds = 餐桌信息BLL.Query();
            this.dataGridView1.DataSource = ds.Tables[0];
        }
    }
}
